<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['types']=array(
	'1'=>'普通防伪码',
	'2'=>'分节防伪码',
	'3'=>'防伪二维码',
);
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 50;
	$params=array('status'=>3,'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['goods_id']){
		$params['goods_id']=$_RQ['goods_id'];
		$return['params']['goods_id']=$_RQ['goods_id'];
	}
	//批号
	if(!empty($_RQ['code'])){
		$params['code']=intval($_RQ['code']);
		$return['params']['code']=$_RQ['code'];
	}
	//备注
	if(!empty($_RQ['sn'])){
		$params['sn']='%'.trim($_RQ['sn']).'%';
		$return['params']['sn']=$_RQ['sn'];
	}
    $fields=array();
    $orderby='id desc';
	$total='';
	$list=pdo_getslice('jy_yxgoodserpfw_code',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($list as &$item){
		$item['beinum']=$item['endnum']-$item['startnum'];
		$item['sn']=sprintf("%08d", $item['sn']);
		$item['startnum']=sprintf("%08d", $item['startnum']);
		$item['endnum']=sprintf("%08d", $item['endnum']);
		$item['pre']=pdo_getcolumn('jy_yxgoodserpfw_batch',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['batch_id']),'pre');
		$item['presn']=$item['pre'].$item['sn'];
		$item['dongtime']=pdo_getcolumn('jy_yxgoodserpfw_log',array('type'=>3,'uniacid'=>$_SESSION['uniacid'],'code'=>$item['code']),'createtime');
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['status']=$this->code_status;
	$return['log_status']=$this->codelog_status;			
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'箱码管理'),
		),
		'list'=>array(
		'tip'=>'防伪的<em>业务逻辑</em>：',
		'data'=>'list','edit'=>false,'delone'=>false,'delall'=>false,'list'=>array(
			array('name'=>'pre','title'=>'前缀','type'=>'string'),
			array('name'=>'sn','title'=>'流水号','type'=>'string'),
			array('name'=>'presn','title'=>'带前缀流水号','type'=>'string'),
			array('name'=>'code','title'=>'防伪码','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'log_status','title'=>'流通状态','type'=>'radio','options'=>'log_status'),
			array('name'=>'dongtime','title'=>'扫码时间','type'=>'time'),
		),
		),
		'search'=>array(			
			array('name'=>'sn','width'=>15,'title'=>'流水号','type'=>'string'),
			array('name'=>'goods_id','width'=>15,'title'=>'所属商品','type'=>'choose','op'=>'jy_yxgoodserpfw/get_goods/'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
?>